package com.xes.apps.ams.scheduler.service;

import javax.inject.Inject;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;

import com.xes.ams.client.api.BaseException;
import com.xes.apps.ams.client.core.service.AttendDataService;
import com.xes.apps.ams.config.ServerConfig;
import com.xes.apps.ams.scheduler.Scheduler;

/***
 * @description 开课前刷卡时间限制参数下载
 * @author wjl
 * @ClassName: DownloadBeginClassTimeService
 * @Version 版本
 * @ModifiedBy wjl
 * @Copyright ers
 * @date 2015年12月03日 上午11:46:05
 */
@Service
public class DownloadBeginClassTimeService implements Scheduler {
	private static final Logger log = LogManager.getLogger(DownloadBeginClassTimeService.class);
	@Inject
	private ServerConfig config;
	@Inject
	private AttendDataService attendDataService;

	@Override
	@Scheduled(fixedDelay = 1000 * 60 * 60)		// 1 hours
	public void execute() {
		StopWatch stopWatch = new StopWatch("开课前刷卡时间限制参数下载服务VenueId：" + config.getAreaCode());
		stopWatch.start("下载");
		Integer beginClassTime = 0;
		try {
			beginClassTime = attendDataService.queryAttendTimeBegin(config.getAreaCode(), config.getBeginClassTime());
			config.setBeginClassTime(beginClassTime);
		} catch (BaseException e) {
			log.error("开课前刷卡时间限制参数下载失败:{}:{},{}", e.getResultCode(), e.getResultCode(), e.getMessage());
		}
		log.info("开课前刷卡时间限制参数下载值:{}分钟", beginClassTime*60);
		stopWatch.stop();
//		log.info(stopWatch.prettyPrint());
	}

}
